
/**
 * Attaches the calendar behavior to all required fields
 */
Drupal.behaviors.date_popup = function(context) {
    for (var id in Drupal.settings.datePopup) {
        $('#' + id).bind('focus', Drupal.settings.datePopup[id], function(e) {
            if (!$(this).hasClass('date-popup-init')) {
                var datePopup = e.data;
                // Explicitely filter the methods we accept.
                switch (datePopup.func) {
                    case 'datepicker':
                        $(this)
                                .datepicker(datePopup.settings)
                                .addClass('date-popup-init')
                        $(this).click(function() {
                            $(this).focus();
                        });
                        break;

                    case 'timeEntry':
                        $(this)
                                .timeEntry(datePopup.settings)
                                .addClass('date-popup-init')
                        $(this).click(function() {
                            $(this).focus();
                        });
                        break;
                }
            }
        });
    }
};
